import { JupiterDictionary, JupiterDictionaryQuery } from '../types/dictionaryTypes';
import request from 'utils/request';

// 获取字典列表
export const fetchDictionaryList = (params: JupiterDictionaryQuery) => {
  return request.post('/dictionaries/page', params);
};

// 获取所有字典
export const fetchAllDictionaries = () => {
  return request.get('/dictionaries');
};

// 根据UUID获取字典
export const fetchDictionaryById = (uuid: string) => {
  return request.get(`/dictionaries/${uuid}`);
};

// 创建字典
export const createDictionary = (data: Partial<JupiterDictionary>) => {
  return request.post('/dictionaries', data);
};

// 更新字典
export const updateDictionary = (uuid: string, data: Partial<JupiterDictionary>) => {
  return request.put(`/dictionaries/${uuid}`, data);
};

// 删除字典
export const deleteDictionary = (uuid: string) => {
  return request.delete(`/dictionaries/${uuid}`);
};

// 根据字典类型获取字典列表
export const fetchDictionariesByType = (dictType: string) => {
  return request.get(`/dictionaries/type/${dictType}`);
};

// 根据父级UUID获取子字典列表
export const fetchDictionariesByParent = (parentUuid: string) => {
  return request.get(`/dictionaries/parent/${parentUuid}`);
};

// 根据字典类型和键获取字典项
export const fetchDictionaryByTypeAndKey = (dictType: string, dictKey: string) => {
  return request.get(`/dictionaries/type/${dictType}/key/${dictKey}`);
};

// 获取激活状态的字典列表
export const fetchActiveDictionariesByType = (dictType: string) => {
  return request.get(`/dictionaries/active/type/${dictType}`);
};
